<template>
	<view class="prohibition w100" v-show="showTab">
		<view class="demo" :style="[{background},{color},{height},{paddingTop}]">
			<!-- 左侧返回按钮 -->
			<view class="left1" @click="onBack" v-if="back" :style="[{color},{paddingTop}]">
				<uni-icons type="back" size="30" color='#000'></uni-icons>
				<!-- 此处图标使用的是 uni-ui图标 -->
			</view>
			<!-- 中间标题文字 -->
			<view class="title">
				{{title}}
			</view>
		</view>
		<view class="footer df-sb pd-rl-30" v-if="showCow">
			<view class="left df-cen">
				<view class="img">
					<image src="/static/img/logo.png" class="bor-500"></image>
				</view>
				<view class="leftName">
					永庆控股
				</view>
			</view>
			<view class="right df-cen">
				<view class="btn bor-50">
					在线咨询
				</view>
				<image src="/static/icon/phone.png" @click="sendPhone"></image>
			</view>
		</view>
	</view>
</template>


<script setup>
	import {ref,onMounted} from 'vue'
	defineProps({
		// 标题必传，且为 String 类型
		title: {
			type: String,
			default: '永庆控股',
			// required: true   //为必传
		},
		// 标题背景色必传，且为 String 类型
		background: {
			type: String,
			default: 'transparent',
		},
		// 标题颜色，且为 String 类型
		color: {
			type: String,
			default: '#000',
		},
		//父组件方法
		sendPhone: {
			type: Function,
		},
		//显示返回键按钮
		back: {
			type: Boolean,
			default: false
		},
		//名字logo显示状态
		showCow: {
			type: Boolean,
			default: false
		},
	})

	// defineProps(['title', 'background', 'color', 'back', 'sendPhone', 'showCow'])
	const height = ref(0)
	const paddingTop = ref(0)
	const showTab = ref(false)
	// #ifdef MP-WEIXIN
	const demo = uni.getMenuButtonBoundingClientRect()
	height.value = demo.height + "px"
	paddingTop.value = demo.top + "px"
	// #endif

	// #ifdef H5
	height.value = 25 + "px"
	paddingTop.value = 10 + "px"
	// #endif

	// 左侧返回按钮调用
	function onBack() {
		uni.navigateBack()
	}

	onMounted(() => {
		uni.$on('onPageScroll', function(data) {
			if (data > 200) {
				showTab.value = true
			} else {
				showTab.value = false
			}
		})
	})
</script>
<script>
	export default {
		name: 'nav-bar'
	}
</script>

<style lang="less">
	.prohibition {
		position: fixed;
		top: 0;
		z-index: 100;
		background-color: #fff;
		// height: 80rpx;
		// display: flex;
		// align-items: center;
	}

	.demo {
		position: relative; //注意，建议使用相对定位，因为固定定位会脱离文档流，然后你还要去设置marginTop值
		// position: fixed;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		z-index: 100;
		padding-bottom: 10rpx;
		.left1 {
			float: left;
			position: absolute;
			width: 100rpx;
			height: 50rpx;
			top: 0;
			bottom: 0;
			left: 20rpx;
			color: #fff;
			display: flex;
			align-items: center;
		}
		

		.title {
			font-size: 36rpx;
			font-weight: 500;
		}
	}

	.footer {
		margin: 80rpx 0rpx 30rpx 0rpx;
		font-size: 28rpx;

		.left {
			.img {
				width: 60rpx;
				height: 60rpx;

				image {
					width: 60rpx;
					height: 60rpx;
				}
			}
		}

		.right {
			image {
				width: 60rpx;
				height: 60rpx;
				margin-left: 10rpx;
			}

			.btn {
				padding: 8rpx 18rpx;
			}
		}
	}
</style>